package com.gem.service.impl;

import com.gem.entity.User;
import com.gem.service.UserService;
import com.gem.factory.user.UserFactory;
import com.gem.utils.R;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Author: Xhy
 * CreateTime: 2022-09-21 14:21
 */
@Service
public class UserServiceImpl implements UserService {
    @Override
    public R createUser(String name) {

        if (name == null || name.length() == 0){
            return R.error().message("取个名字吧");
        }

        String userId = UserFactory.createUser(name);
        return R.ok().message("创建成功").data("userId",userId);
    }

    @Override
    public R remove(String userId) {
        if (UserFactory.existUser(userId)){
            UserFactory.remove(userId);
        }
        return R.ok().message("删除成功");
    }

    @Override
    public R list() {
        return R.ok().data("data",UserFactory.listUsers());
    }

    @Override
    public List<User> selectUsers(List<String> users) {

        return UserFactory.selectUsers(users);
    }
}
